package com.atguigu.tingshu.album.rpc;

import com.atguigu.tingshu.album.service.AlbumInfoService;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.album.service.TrackInfoService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.AlbumInfo;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.model.album.BaseCategoryView;
import com.atguigu.tingshu.model.album.TrackInfo;
import com.atguigu.tingshu.vo.album.AlbumStatVo;
import com.atguigu.tingshu.vo.album.TrackListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/rpc/inner/albumInfo")
public class AlbumInfoRpcController {

    @Autowired
    private AlbumInfoService albumInfoService;

    @Autowired
    private BaseCategoryService baseCategoryService;

    @Autowired
    private TrackInfoService trackInfoService;


    @GetMapping("/getAlbumInfo/{albumId}")
    public Result<AlbumInfo> getAlbumInfo(@PathVariable Long albumId) {
        return Result.ok(albumInfoService.getAlbumInfo(albumId));
    }

    @GetMapping("/getCategory/{albumId}")
    Result<BaseCategoryView> getCategory(@PathVariable Long albumId) {
        BaseCategoryView baseCategoryView = baseCategoryService.getCategory(albumId);
        return Result.ok(baseCategoryView);
    }

    @GetMapping("/getAlbumStat/{albumId}")
    Result<AlbumStatVo> getAlbumStat(@PathVariable Long albumId) {
        AlbumStatVo albumStatVo = albumInfoService.getAlbumStat(albumId);
        return Result.ok(albumStatVo);
    }

    @GetMapping("/getBaseCategory3ListByCategory1Id/{category1Id}")
    Result<List<BaseCategory3>> getBaseCategory3ListByCategory1Id(@PathVariable Long category1Id){
        return Result.ok(baseCategoryService.findTopBaseCategory3(category1Id));
    }

    @GetMapping("/getC1Ids")
    Result<List<Long>> getC1Ids(){
        return Result.ok(baseCategoryService.getC1Ids());
    }

    @PostMapping("/getTrackListByIds")
    Result<List<TrackListVo>> getTrackListByIds(@RequestBody List<Long> trackIds){
        return Result.ok(trackInfoService.getTrackListByIds(trackIds));
    }

    @GetMapping("/getAlbumIds")
    Result<List<Long>> getAlbumIds(){
        return Result.ok(albumInfoService.findAllAlbumId());
    }

    @GetMapping("/getTrackListByCurrentTrackId/{userId}/{trackId}/{trackCount}")
    Result<List<TrackInfo>> getTrackListByCurrentTrackId(@PathVariable Long userId,
                                                         @PathVariable Long trackId,
                                                         @PathVariable Integer trackCount){
        List<TrackInfo> trackInfoList = trackInfoService.getTrackListByCurrentTrackId(userId, trackId, trackCount);
        return Result.ok(trackInfoList);
    }

    @GetMapping("/getTrackInfoByTrackId/{trackId}")
    Result<TrackInfo> getTrackInfoByTrackId(@PathVariable Long trackId){
        return Result.ok(trackInfoService.getById(trackId));
    }

    @GetMapping("/getAlbumInfoByTrackId/{trackId}")
    Result<AlbumInfo> getAlbumInfoByTrackId(@PathVariable Long trackId){
        return Result.ok(albumInfoService.getAlbumInfoByTrackId(trackId));
    }
}
